import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { User } from '../users/users.entity';

@Entity('diamond_transactions')
export class DiamondTransaction {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @Column({ name: 'user_id' })
  userId: number;

  @Column({ type: 'int' })
  amount: number; // 正数为收入，负数为支出

  @Column({ name: 'balance_after', type: 'int' })
  balanceAfter: number; // 交易后余额

  @Column({
    name: 'transaction_type',
    type: 'enum',
    enum: ['recharge', 'purchase', 'reward', 'refund'],
  })
  transactionType: 'recharge' | 'purchase' | 'reward' | 'refund';

  @Column({ name: 'related_id', nullable: true })
  relatedId: number; // 关联ID（如订单ID）

  @Column({ length: 255, nullable: true })
  description: string;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;
}
